﻿using System.Collections;
using System.Collections.Generic;
using System;
using System.Text;
using DAL;
using BLL;
using System.IO;
using System.Data;
using System.Xml;
using System.Web.Security;
using System.Security.Cryptography;
using System.Net;
using System.Web;


namespace Web.Old_App_Code
{

    public class PageListNo
    {
        // Methods
        public void DelPageSize(DataTable dt, int total)
        {
            if ((total > 0) && (dt.Rows.Count == 0))
            {
                string query = HttpContext.Current.Request.Url.Query;
                string url = HttpContext.Current.Request.Url.LocalPath + "?";
                bool flag = false;
                Array array = query.Substring(1).Split(new char[] { '&' });
                foreach (string str3 in array)
                {
                    Array array2 = str3.Split(new char[] { '=' });
                    if (array2.GetValue(0).ToString() != "p")
                    {
                        if (!flag)
                        {
                            url = url + array2.GetValue(0).ToString() + "=" + array2.GetValue(1).ToString();
                            flag = true;
                        }
                        else
                        {
                            string str4 = url;
                            url = str4 + "&" + array2.GetValue(0).ToString() + "=" + array2.GetValue(1).ToString();
                        }
                    }
                }
                int num = Convert.ToInt32(HttpContext.Current.Request.QueryString["p"]) - 1;
                if (!flag)
                {
                    url = url + "p=" + num.ToString();
                }
                else
                {
                    url = url + "&p=" + num.ToString();
                }
                HttpContext.Current.Response.Redirect(url);
            }
        }

        public StringBuilder DisplayPage(int total, int pageSize, int pageIndex)
        {
            StringBuilder builder = new StringBuilder();
            int pageCount = ((total % pageSize) == 0) ? (total / pageSize) : ((total / pageSize) + 1);
            if (pageCount > 0)
            {
                string str7;
                builder.AppendLine(string.Concat(new object[] { "<div class=\"pagebottom\"><span class=\"total\">总记录数：<strong>", total, "</strong>共", pageCount, "页</span>" }));
                if (pageIndex != 1)
                {
                    string str = "<a href=\"?p=1";
                    string str2 = "<a href=\"?p=" + (pageIndex - 1);
                    if (HttpContext.Current.Request.QueryString.AllKeys.Length > 0)
                    {
                        foreach (string str3 in HttpContext.Current.Request.QueryString.AllKeys)
                        {
                            if (str3 != "p")
                            {
                                str7 = str;
                                str = str7 + "&" + str3 + "=" + HttpContext.Current.Request.QueryString[str3];
                                str7 = str2;
                                str2 = str7 + "&" + str3 + "=" + HttpContext.Current.Request.QueryString[str3];
                            }
                        }
                    }
                    str = str + "\">首页</a>";
                    str2 = str2 + "\">上一页</a>";
                    builder.AppendLine(str);
                    builder.AppendLine(str2);
                }
                else
                {
                    builder.AppendLine("<span class=\"disabled\"> 首页 </span>");
                    builder.AppendLine("<span class=\"disabled\"> 上一页 </span>");
                }
                foreach (int num2 in new PageListNo().get_midpageno(pageIndex, 10, pageCount))
                {
                    if (num2 == pageIndex)
                    {
                        builder.AppendLine("<span class=\"current\">" + num2 + "</span>");
                    }
                    else
                    {
                        string str4 = "<a href=\"?p=" + num2;
                        if (HttpContext.Current.Request.QueryString.AllKeys.Length > 0)
                        {
                            foreach (string str3 in HttpContext.Current.Request.QueryString.AllKeys)
                            {
                                if (str3 != "p")
                                {
                                    str7 = str4;
                                    str4 = str7 + "&" + str3 + "=" + HttpContext.Current.Request.QueryString[str3];
                                }
                            }
                        }
                        object obj2 = str4;
                        str4 = string.Concat(new object[] { obj2, "\">", num2, "</a>" });
                        builder.AppendLine(str4);
                    }
                }
                if ((pageIndex != pageCount) && (pageCount > 0))
                {
                    string str5 = "<a href=\"?p=" + (pageIndex + 1);
                    string str6 = "<a href=\"?p=" + pageCount;
                    if (HttpContext.Current.Request.QueryString.AllKeys.Length > 0)
                    {
                        foreach (string str3 in HttpContext.Current.Request.QueryString.AllKeys)
                        {
                            if (str3 != "p")
                            {
                                str7 = str5;
                                str5 = str7 + "&" + str3 + "=" + HttpContext.Current.Request.QueryString[str3];
                                str7 = str6;
                                str6 = str7 + "&" + str3 + "=" + HttpContext.Current.Request.QueryString[str3];
                            }
                        }
                    }
                    str5 = str5 + "\">下一页</a>";
                    str6 = str6 + "\">尾页</a>";
                    builder.AppendLine(str5);
                    builder.AppendLine(str6);
                }
                else if (pageIndex == pageCount)
                {
                    builder.AppendLine("<span class=\"disabled\"> 下一页 </span>");
                    builder.AppendLine("<span class=\"disabled\"> 尾页 </span>");
                }
                builder.AppendLine(string.Concat(new object[] { "<input id=\"txtGotoPage\" type=\"text\" maxlength=\"6\" class=\"shorttxt\" onpaste=\"return false\" style=\"ime-mode:disabled\" onkeypress=\"if ((event.keyCode<48 || event.keyCode>57||event.keyCode==46)) event.returnValue=false\" value=\"", (HttpContext.Current.Request.QueryString["p"] != null) ? HttpContext.Current.Request.QueryString["p"] : "", "\" /><input id=\"btnGotoPage\" type=\"button\" class=\"formButton\" value=\"跳转\" onclick=\"GotoPage(", pageCount, ");\" />" }));
                builder.AppendLine("</div>");
            }
            return builder;
        }

        public StringBuilder FrontDeskDisplayPage(int total, int pageSize, int pageIndex)
        {
            StringBuilder builder = new StringBuilder();
            int pageCount = ((total % pageSize) == 0) ? (total / pageSize) : ((total / pageSize) + 1);
            if (pageCount > 0)
            {
                string str7;
                builder.AppendLine(string.Concat(new object[] { "<div class=\"pagebottom\"><span class=\"total\">总记录数：<strong>", total, "</strong>共", pageCount, "页</span>" }));
                if (pageIndex != 1)
                {
                    string str = "<a href=\"?p=1";
                    string str2 = "<a href=\"?p=" + (pageIndex - 1);
                    if (HttpContext.Current.Request.QueryString.AllKeys.Length > 0)
                    {
                        foreach (string str3 in HttpContext.Current.Request.QueryString.AllKeys)
                        {
                            if (str3 != "p")
                            {
                                str7 = str;
                                str = str7 + "&" + str3 + "=" + HttpContext.Current.Request.QueryString[str3];
                                str7 = str2;
                                str2 = str7 + "&" + str3 + "=" + HttpContext.Current.Request.QueryString[str3];
                            }
                        }
                    }
                    str = str + "\" title=\"首页\">首页</a>";
                    str2 = str2 + "\" title=\"上一页\" class=\"prepage\">上一页</a>";
                    builder.AppendLine(str);
                    builder.AppendLine(str2);
                }
                else
                {
                    builder.AppendLine("<span class=\"disabled\" title=\"首页\">首页</span>");
                    builder.AppendLine("<span class=\"disabled prepage\" title=\"上一页\">上一页</span>");
                }
                foreach (int num2 in new PageListNo().get_midpageno(pageIndex, 10, pageCount))
                {
                    if (num2 == pageIndex)
                    {
                        builder.AppendLine("<span class=\"current\">" + num2 + "</span>");
                    }
                    else
                    {
                        string str4 = "<a href=\"?p=" + num2;
                        if (HttpContext.Current.Request.QueryString.AllKeys.Length > 0)
                        {
                            foreach (string str3 in HttpContext.Current.Request.QueryString.AllKeys)
                            {
                                if (str3 != "p")
                                {
                                    str7 = str4;
                                    str4 = str7 + "&" + str3 + "=" + HttpContext.Current.Request.QueryString[str3];
                                }
                            }
                        }
                        object obj2 = str4;
                        str4 = string.Concat(new object[] { obj2, "\">", num2, "</a>" });
                        builder.AppendLine(str4);
                    }
                }
                if ((pageIndex != pageCount) && (pageCount > 0))
                {
                    string str5 = "<a href=\"?p=" + (pageIndex + 1);
                    string str6 = "<a href=\"?p=" + pageCount;
                    if (HttpContext.Current.Request.QueryString.AllKeys.Length > 0)
                    {
                        foreach (string str3 in HttpContext.Current.Request.QueryString.AllKeys)
                        {
                            if (str3 != "p")
                            {
                                str7 = str5;
                                str5 = str7 + "&" + str3 + "=" + HttpContext.Current.Request.QueryString[str3];
                                str7 = str6;
                                str6 = str7 + "&" + str3 + "=" + HttpContext.Current.Request.QueryString[str3];
                            }
                        }
                    }
                    str5 = str5 + "\" title=\"下一页\" class=\"nextpage\">下一页</a>";
                    str6 = str6 + "\" title=\"尾页\">尾页</a>";
                    builder.AppendLine(str5);
                    builder.AppendLine(str6);
                }
                else if (pageIndex == pageCount)
                {
                    builder.AppendLine("<span class=\"disabled nextpage\" title=\"下一页\">下一页</span>");
                    builder.AppendLine("<span class=\"disabled\" title=\"尾页\">尾页</span>");
                }
                builder.AppendLine("</div>");
            }
            return builder;
        }

        public List<int> get_midpageno(int pageindex, int display_count, int PageCount)
        {
            int num2;
            List<int> list = new List<int>();
            int num = display_count / 2;
            if (PageCount > display_count)
            {
                if (pageindex <= num)
                {
                    for (num2 = 1; num2 < (display_count + 1); num2++)
                    {
                        list.Add(num2);
                    }
                }
                if (pageindex > (PageCount - num))
                {
                    for (num2 = (PageCount - display_count) + 1; num2 < (PageCount + 1); num2++)
                    {
                        list.Add(num2);
                    }
                }
                if ((pageindex > num) && (pageindex <= (PageCount - num)))
                {
                    for (num2 = pageindex - num; num2 < ((pageindex + num) + 1); num2++)
                    {
                        list.Add(num2);
                    }
                }
                return list;
            }
            for (num2 = 1; num2 < (PageCount + 1); num2++)
            {
                list.Add(num2);
            }
            return list;
        }
    }

}
 
